package com.sakiko.controller;

import com.sakiko.pojo.Schedule;
import com.sakiko.service.ScheduleService;
import com.sakiko.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin // 解决跨域问题
@RestController
@RequestMapping("schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    // 查询所有学习计划
    @GetMapping
    public R scheduleList() {
        List<Schedule> serviceAll = scheduleService.getAll();

        return R.ok(serviceAll);
    }

    // 删除学习计划
    @DeleteMapping("{id}")
    public R deleteSchedule(@PathVariable int id) {
        scheduleService.removeById(id);
        return R.ok(null);
    }

    // 保存学习计划
    @PostMapping
    public R addSchedule(@RequestBody Schedule schedule) {
        scheduleService.saveSchedule(schedule);
        return R.ok(null);
    }

    // 更新学习计划
    @PutMapping
    public R update(@RequestBody Schedule schedule) {
        scheduleService.updateSchedule(schedule);
        return R.ok(null);
    }

}
